package com.taotao.rest.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.po.TbContent;
import com.taotao.pojo.TaotaoResult;
import com.taotao.rest.service.ContentService;
import com.taotao.util.ExceptionUtil;

@Controller

public class ContentController {

	@Autowired
	private ContentService contentService;
	
	@RequestMapping(value="/content/{cid}",produces=MediaType.APPLICATION_JSON_VALUE+";charset=utf-8")
	@ResponseBody
	public TaotaoResult getContentList(@PathVariable Long cid) {
		try {
			List<TbContent> list = contentService.getContentList(cid);
			return TaotaoResult.ok(list);
		} catch (Exception e) {
			// 如果发生错误就返回错误信息
			e.printStackTrace();
			return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
		}
	}

	@RequestMapping("/sync/content/{cid}")
	@ResponseBody
	public TaotaoResult sysncContent(@PathVariable Long cid)
	{
		try {
			TaotaoResult result = contentService.synchronizedContent(cid);
			return result;
		} catch (Exception e) {			
			// 如果发生错误就抓取返回
			e.printStackTrace();
			return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
		}
	}
}
